from PyQt5.Qt import *
import sys

class QAPP(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()

    def setup_ui(self):
        self.setWindowTitle("单选按钮控件")
        self.resize(200, 100)
        layout=QHBoxLayout()

        self.button1=QRadioButton("单选按钮1")
        self.button1.setChecked(True)
        self.button1.toggled.connect(self.buttonState)
        layout.addWidget(self.button1)

        self.button2=QRadioButton("单选按钮2")
        #self.button2.setChecked(True)
        self.button2.toggled.connect(self.buttonState)
        layout.addWidget(self.button2)

        self.setLayout(layout)

    def buttonState(self):
        radioButton=self.sender()
        if radioButton.isChecked()==True:
            print(radioButton.text()+"被选中")
        else:
            print(radioButton.text()+"没有被选")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    my = QAPP()
    my.show()
    sys.exit(app.exec_())